;;; -*- Emacs-Lisp -*-

;; Time-stamp: <2013-01-12 16:24:17 Saturday by qwy>
;; 我自己的配置文件，按你的要求修改就好，注意pull后会被覆盖
;; 按键上尽量参照phpstorm

;;;qwy
(defconst  my-emacs-path        "~/.emacs.d/qwy/" "我的emacs相关配置文件的路径")
(menu-bar-mode 1)

;;;这个是find,grep的path路径，由于git会自带msys，所以直接用msys的bin
;;;在windows下这个是必装，很多emacs功能都是配合linux的命令使用的。目前的方案是安装git，然后用git的msys
(setenv "PATH"
        (concat
         ;; Change this with your path to MSYS bin directory
         "d:\\Program Files\\Git\\usr\\bin;"
         (getenv "PATH")))

                                        ;magit的.gitconfig配置要手工加在home下面

;;;todo
(setq todo-file-do "~/todo-do")
(setq todo-file-done "~/todo-done")
(setq todo-file-top "~/todo-top")

;;diary
(setq diary-file "~/qwy_diary")
(setq mark-diary-entries-in-calendar t)
(setq diary-mail-addr "419557780@qq.com")
(add-hook 'diary-hook 'appt-make-list)
;(global-set-key [(control f11)] 'calendar)

;;;列举书签
(global-set-key (kbd "<f12> w") 'list-bookmarks)

;;;从书签移除
(global-set-key (kbd "<f12> d") 'bookmarks-delete)

;;;添加当前页至文件书签
(global-set-key (kbd "<f12> a") 'bookmark-set)

;;;F12 u 更新当前版本
;;(global-set-key (kbd "<f12> u") 'vc-next-action)

;高亮选中的region
(setq transient-mark-mode t)

;; qwy
(global-set-key [?\C-\]] 'set-mark-command)  ;c-[ 开始标记
(global-set-key [\c-\/] 'comment-region)    ;c-/ 注释
(global-set-key [?\M-/] 'uncomment-region)  ;m-/ 取消注释


;; 停用C-z,在win下是最小化，绑定到撤消
(global-set-key "\C-z" nil)
(global-set-key [?\C-z] 'undo)
;; 启用c-v 粘贴
(global-set-key [?\C-v] 'yank)

;;修改标识的相关按键
(global-set-key (kbd "C-M-]") 'mark-sexp)

                                        ;(pc-selection-mode t)

;;;定义宏,用于修改asp网站(公司的历史遗留网站)
;;;生成title = request.form("title")
(fset 'getaspform
      "\C-a\C-]\C-e\367 = request.form(\"\C-v\")\C-n")

(global-set-key (kbd "C-c f") 'getaspform)

;生成rs("title")=title形式
(fset 'getasprs
   "\C-a\C-]\C-e\367\C-ars(\"\C-e\") = \C-v\C-n")

(global-set-key (kbd "C-c r") 'getasprs)

;;;;备份策略
(setq backup-directory-alist '(("" . "d:/tmp/emacs")))
(setq-default make-backup-file t)
                                        ;(setq make-backup-file t)
(setq make-backup-files t)
(setq version-control t)
(setq kept-old-versions 2)
(setq kept-new-versions 10)
(setq delete-old-versions t)

                                        ;(pc-selection-mode)

;;调用一个py脚本，作用是把当前buffer的文件自动上传至ftp(py会自行判断到哪个ftp站点)
(defun qwyftpUpload(&optional arg)
  (interactive "P")
  (setq fname (buffer-file-name))
  (message "Running...")
  (setq progName "python d:/worksync/script/ftpupload.py ")
  (setq cmdStr (concat progName " \""   fname "\""))
  (shell-command cmdStr)
  (message "Finish")
  )

(global-set-key (kbd "C-c e") (quote qwyftpUpload))

(defun switch-to-scratch ()
  "切换到*scratch*"
  (interactive)
  (let ((buffer (get-buffer-create "*scratch*")))
    (switch-to-buffer buffer)
    (unless (equal major-mode 'lisp-interaction-mode)
      (lisp-interaction-mode))))
(global-set-key (kbd "<f12> s") 'switch-to-scratch)


;;f11 打开一个类似notepad一样的窗口
(defun notepad-new-frame ()
  (interactive)
  (switch-to-buffer-other-frame (get-buffer-create "*notepad*"))
  (text-mode)
  )
(global-set-key (kbd "<f11>") 'notepad-new-frame)

;;;C-x E 直接访问配置文件
(defun visitqwy.emacs ()
  "访问.emacs文件"
  (interactive)
  (find-file ("~/.emacs.d/qwy/hkcat-settings.el")))
(global-set-key (kbd "C-x E") 'visitqwy.emacs)

(setq initial-major-mode 'text-mode)
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . html-mode))

;;; f9 打开文件所在文件夹
(defun explorer ()
  "Launch the windows explorer in the current directory and selects current file"
  (interactive)
  (w32-shell-execute
   "open"
   "explorer"
   (concat "/e,/select," (convert-standard-filename buffer-file-name))))

(global-set-key [f9] 'explorer)


;;;设置英文字体consolas和中文字体微软雅黑
(set-face-attribute
 'default nil :font "Consolas 11")

(dolist (character '(han kana symbol cjk-misc bopomofo))
(set-fontset-font (frame-parameter nil 'font)
character
(font-spec :family "Microsoft YaHei" :size 16)))

;;;快速连接到3389远程服务器
(defun startgd()
  "Launch the Remote with RDP file"
  (interactive)
  (start-process-shell-command "gdrdp" "gdrdp" "mstsc " " d:/qwy_work/start/gd.rdp" "")
  )

(defun startxg()
  "Launch the Remote with RDP file"
  (interactive)
  (start-process-shell-command "xgrdp" "xgrdp" "mstsc " " d:/qwy_work/start/xg.rdp"  "")
  )

;;;为了兼容原ahei配置而引入，已停用
;;;(load-file  "~/.emacs.d/qwy/eval-after-load.el")
;;;(require 'eval-after-load)

;;;加载neotree
(global-set-key [f8] 'neotree-toggle)


;;; 加载theme,可以改成你自己的配色方案
(require-package 'color-theme-modern)
(load-theme 'dark-blue2 t t )
(enable-theme 'dark-blue2)

;;; 加载yas
(require-package 'yasnippet)
(load-file  "~/.emacs.d/qwy/yasnippet-settings.el")
(yasnippet-settings)

;;;载入zencoding
(require-package 'zencoding-mode)
;;;(require 'zencoding-mode)
(add-hook 'sgml-mode-hook 'zencoding-mode)
(add-hook 'zencoding-mode-hook  '(lambda () (define-key zencoding-mode-keymap (kbd "<M-return>") 'zencoding-expand-line)))

;;;载入nyan-mode
;;;todo:放在了配置目录，还需要修改
(load-file  "~/.emacs.d/qwy/nyan-mode.el")
(nyan-mode)

                                        ;(load-file  "~/.emacs.d/qwy/house5-mode.el")
                                        ;(house5-mode)

;;;载入torsvn, 由于全部升级为git了，所以停用svn
                                        ;(load-file  "~/.emacs.d/qwy/tortoisesvn-mode.el")
                                        ;(tortoisesvn-mode)

;;;配置.htaccess的语法高亮
(require 'generic-x)
(define-generic-mode 'htaccess-mode
  '(?#)
  '(;; core
    "AcceptPathInfo" "AccessFileName" "AddDefaultCharset" "AddOutputFilterByType"
    "AllowEncodedSlashes" "AllowOverride" "AuthName" "AuthType"
    "CGIMapExtension" "ContentDigest" "DefaultType" "DocumentRoot"
    "EnableMMAP" "EnableSendfile" "ErrorDocument" "ErrorLog"
    "FileETag" "ForceType" "HostnameLookups" "IdentityCheck"
    "Include" "KeepAlive" "KeepAliveTimeout" "LimitInternalRecursion"
    "LimitRequestBody" "LimitRequestFields" "LimitRequestFieldSize" "LimitRequestLine"
    "LimitXMLRequestBody" "LogLevel" "MaxKeepAliveRequests" "NameVirtualHost"
    "Options" "Require" "RLimitCPU" "RLimitMEM"
    "RLimitNPROC" "Satisfy" "ScriptInterpreterSource" "ServerAdmin"
    "ServerAlias" "ServerName" "ServerPath" "ServerRoot"
    "ServerSignature" "ServerTokens" "SetHandler" "SetInputFilter"
    "SetOutputFilter" "TimeOut" "UseCanonicalName"
    ;; .htaccess tutorial
    "AddHandler" "AuthUserFile" "AuthGroupFile"
    ;; mod_rewrite
    "RewriteBase" "RewriteCond" "RewriteEngine" "RewriteLock" "RewriteLog"
    "RewriteLogLevel" "RewriteMap" "RewriteOptions" "RewriteRule"
    ;; mod_alias
    "Alias" "AliasMatch" "Redirect" "RedirectMatch" "RedirectPermanent"
    "RedirectTemp" "ScriptAlias" "ScriptAliasMatch")
  '(("%{\\([A-Z_]+\\)}" 1 font-lock-variable-name-face)
    ("\\b[0-9][0-9][0-9]\\b" . font-lock-constant-face)
    ("\\[.*\\]" . font-lock-type-face))
  '(".htaccess\\'")
  nil
  "Generic mode for Apache .htaccess files.")


;;plink.exe用putty目录下的，并加到path中
;;通过C-x C-f /plink:root@11.11.1.1:/home来访问
(require 'tramp)
(setq tramp-default-method "plink"
      tramp-password-end-of-line "\r\n")
(setq password-cache-expiry 36000)
;;cygwin的ftp.exe和windows10自带的ftp一样会卡死，所以停用了
;;(setq ange-ftp-ftp-program-name "D:/qwy_work/soft/cygwin/bin/ftp.exe")
;;这个ftp是emacs wiki上推荐的版本。ftp://ftp.gnu.org/old-gnu/emacs/windows/contrib/ftp-for-win32.zip
(setq ange-ftp-ftp-program-name "~/bin/ftp.exe")
(setq ange-ftp-try-passive-mode t)
;;增加证书登陆，下面的ppk路径改成你的证书路径(ppk格式)
;;通过C-x C-f /plinkzs:root@1.1.1.1:/home来访问
(add-to-list 'tramp-methods
             '("sshzs"
               (tramp-login-program "plink")
               (tramp-login-args
                (("-l" "%u")
                 ("-P" "%p")
                 ("-ssh")
                 ("-t")
                 ("%h")
                 ("-i" "c:/Users/41955/.ssh/id_rsa.ppk")))
               (tramp-remote-shell "/bin/sh")
               (tramp-remote-shell-args
                ("-c"))
               (tramp-default-port 22)))

;;;(setq flycheck-mode nil)
;;; 尝试关闭全局的语法检测，但未生效，以后再找原因
(setq global-flycheck-mode nil)

;;markdown
;;先安装pandoc并加到path中
(custom-set-variables
 '(markdown-command "pandoc"))

;;git路径定义，由于目前用的git已在path中，所以不用手工指定了
;;(add-to-list 'exec-path "D:/Program Files/Git/bin")

(setq read-quoted-char-radix 10)

;;php相关
(setq php-completion-file "~/.emacs.d/php-completion-file")  ;php函数补全文件
(setq php-manual-path "~/.emacs.d/php_manual_zh")  ;php手册目录，先下载好中文html版

(setq php-manual-url 'zh)
(add-hook 'php-mode-hook  '(lambda () (define-key php-mode-map (kbd "C-c o") 'php-complete-function))) ;C-c o 补全php函数名

(defun wordpress-function-lookup ()
  "Look up the wordpress function under cursor in a browser."
  (interactive)
  (browse-url
   (concat "https://codex.wordpress.org/Function_Reference/" (thing-at-point 'symbol))))
(add-hook 'php-mode-hook  '(lambda () (define-key php-mode-map (kbd "C-c w") 'wordpress-function-lookup))) ;C-c o 查询wordpress文档

;;按网上提供的编码方案，设置编码为utf8
(setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters)
(set-language-environment 'utf-8)
(set-keyboard-coding-system 'utf-8-mac) ; For old Carbon emacs on OS X only
(setq locale-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(unless (eq system-type 'windows-nt)
  (set-selection-coding-system 'utf-8))
(prefer-coding-system 'utf-8)

;;两行合并为一行,
;;多行可用替换c-q c-j的方法
(defun join-lines (arg)
  (interactive "p")
  (end-of-line)
  (delete-char 1)
  (delete-horizontal-space)
  (insert " "))

;;vue-mode
'(mmm-default-submode-face ((t (:background "#233B5A"))))

;;projectile配置
(setq projectile-indexing-method 'hybrid)
(setq projectile-sort-order 'recentf)

;;;python-mode
;;采用jedi作为py后端补全
;; (with-eval-after-load 'company
;;   (add-hook 'python-mode-hook
;;             (lambda ()
;;               (add-to-list 'company-backends 'company-jedi))))
;;使用anaconda来配合py开发，因为github上更新快
(add-hook 'python-mode-hook 'anaconda-mode)

(provide 'hkcat-settings)
